home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / Virtual User 1.0b5 / Example Scripts / ResEditTest.vu < prev    next >
Encoding:
Text File  |  1990-10-05  |  9.6 KB  |  274 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        ResEditTest.vu
  3. #
  4. #    Contains:    A ResEdit script that creates a window for each of the predefined resource types.
  5. #                If you have a file called "vu-wants-1-of-each" on the topmost volume, this script
  6. #                will delete it and recreate it.  This name is kept in a string called Res_file_name
  7. #                and can be changed if desired.
  8. #
  9. #                This script does quite a bit so it takes a while to execute.  If you would rather
  10. #                have it create some number of resource type windows less than the total, pass a 
  11. #                second parameter to create_one_of_each_type() which indicates the number of resource
  12. #                types you'd like created.  The following call will create the first 15 resource types:
  13. #                    
  14. #                    create_one_of_each_type(true,15);
  15. #                    
  16. #                The first parameter is reserved for future use.  It will be used when the script is
  17. #                extended to actually create resources within the resource type windows.
  18. #
  19. #                This script demonstrates how to use the scroll command to scroll through a scrolling
  20. #                list of items.  Run it and watch what it does with scrolling.
  21. #
  22. #    Starting Configuration:    In order for the script to run properly, the target should be running
  23. #                            ResEdit.  The active window should be a ResEdit window representing 
  24. #                            a volume.  Key repeat should be turned off.
  25. #
  26. #    Conventions:    Global variables begin with a capital letter.
  27. #
  28. #    Written by:    Jay Jessen
  29. #
  30. #    Copyright:    © 1989 by Apple Computer, Inc., all rights reserved.
  31. #
  32. #    Change History:
  33. #
  34. #         5/15/90   JAS        A few formatting changes
  35. #
  36. #         6/7/89       Jay        created from an old version (optimized scrolling actions)
  37. #
  38. #    To Do:
  39. #
  40.  
  41. # ********************************************************************************************
  42. # Selects a menu item using the keyboard alias 
  43. task use_keyboard_equiv(alias) begin
  44.     pressKey k: { commandKey };
  45.     type k: { alias };
  46.     releaseKey k: { commandKey };
  47. end; # end use_keyboard_equiv() 
  48.  
  49.  
  50. # ********************************************************************************************
  51. # Sets globals for window positioning taking into consideration the target screen size 
  52. task set_screen_dependents() begin
  53.     global Wind_x := 250;# hardwired for now
  54.     global Wind_y := 20;# hardwired for now
  55. end; # end set_screen_dependents()
  56.  
  57.  
  58. # ********************************************************************************************
  59. # Creates a valid resource file 
  60. task create_resource_file(res_file_name) begin
  61.  
  62.     global Volume_name;
  63.     
  64.     if(not match[window t:Volume_name o:1]!) begin
  65.         select [window t:Volume_name]!;
  66.     end;
  67.     select [menuItem title:'New' m:'File']!;
  68.     type keystrokes: { res_file_name };
  69.     select [button title:'OK']!;
  70.     if(match[button t:'OK' w:[window o:1]]!) begin # file already exists
  71.         select [button t:'OK']!;
  72.         select [button t:'Cancel']!;
  73.         clear_file(res_file_name);
  74.         select [menuItem title:'New' m:'File']!;
  75.         type keystrokes: { res_file_name };
  76.         select [button title:'OK']!;
  77.     end;
  78. end; # end create_resource_file() 
  79.  
  80.  
  81. # ********************************************************************************************
  82. # Clears a file from Volume window, if check_selection is false it'll clear the current selection 
  83. task clear_file(file_to_clear,check_selection := true) begin
  84.     
  85.     global Volume_name;
  86.     
  87.     if(not match[window t:Volume_name o:1]!) begin
  88.         select [window t:Volume_name]!;
  89.     end;
  90.     if(check_selection) begin
  91.         type k: { "v" };
  92.         found_it := false;
  93.         while not found_it begin
  94.             use_keyboard_equiv("o");
  95.             if(match[staticText t:/The file≈has no resource fork≈Do you wish≈it ∂?/
  96.                                                                     w:[window o:1 s:dialog]]!) begin
  97.                 select [button t:'Cancel']!;
  98.                 type k: { downarrowKey };
  99.             end;
  100.             else begin
  101.                 if (((match[window o:1]!).title) = file_to_clear) begin
  102.                     found_it := true;
  103.                     close [window o:1]!;
  104.                 end;
  105.                 else begin
  106.                     close [window o:1]!;
  107.                     type k: { downarrowKey };
  108.                 end;
  109.             end;
  110.         end;
  111.     end;
  112.     select [menuItem t:'Clear' m:'Edit']!;
  113.     if match[button t:'OK']! and match[button t:'Cancel']! select [button t:'OK'];
  114. end;# end clear_file() 
  115.  
  116.  
  117. # ********************************************************************************************
  118. # Set global values for scroll bar in "Select New Type" dialog 
  119. task set_scroll_bar_globals() begin
  120.  
  121.     global Scrollbar_left,Scrollbar_top,Scrollbar_right,Scrollbar_bottom;
  122.     global Previous_scroller_setting;
  123.  
  124.     select [menuItem title:'New' m:'File']!;
  125.     
  126.     # get the "select new type" dialog's bounding rect and put it in wind_rect
  127.     match [window ord:1 rect:?wind_rect]!;
  128.     
  129.     # get the scroll bar's current setting and rectangle (in local coords)
  130.     current_scroller := match [scrollBar    window_owner:[window ord:1]
  131.                                             setting:?cntrl_value
  132.                                             rect:?scroller_rect]!;
  133.     
  134.     # compute scroll bar rect in global coordinates (8 compensate for the dialog border pixels)
  135.     Scrollbar_left := scroller_rect[1];
  136.     Scrollbar_top := scroller_rect[2];
  137.     Scrollbar_right := scroller_rect[3];
  138.     Scrollbar_bottom := scroller_rect[4];
  139.     
  140.     if(cntrl_value[1] = cntrl_value[2]) begin
  141.         global Done_scrolling := true;
  142.     end;
  143.     else begin
  144.         Previous_scroller_setting := cntrl_value;# keep current setting
  145.     end;
  146. end;# end set_scroll_bar_globals() 
  147.  
  148.  
  149. # ********************************************************************************************
  150. # Positions a resource type window 
  151. task position_res_type_window() begin
  152.     drag [window ord:1] absolute:{ global Wind_x,global Wind_y };
  153.     Wind_x := Wind_x + 1;
  154.     Wind_y := Wind_y + 2;
  155. end; # end position_res_type_window() 
  156.  
  157.  
  158. # ********************************************************************************************
  159. # Scrolls to the next resource type in the "Select New Type" dialog 
  160. task select_next_type() begin
  161.  
  162.     global Previous_scroller_setting,Clicks_for_current_value;
  163.     global Done_scrolling;
  164.     global List_item_height;
  165.     global Scrollbar_left,Scrollbar_top,Scrollbar_right,Scrollbar_bottom;
  166.     global Non_top_item_selection;
  167.     
  168.     scroll [scrollBar w:[window o:1]] absolute: Previous_scroller_setting;
  169.     if(Done_scrolling) begin # ~~ only need to select the remaining visible items (no more scrolling)
  170.         move absolute: { Scrollbar_left - 10,
  171.                     Scrollbar_top + ((Non_top_item_selection - 1) * List_item_height) + 5 };
  172.         Non_top_item_selection := Non_top_item_selection + 1;
  173.     end;
  174.     else begin 
  175.         move absolute: { Scrollbar_right - 5,Scrollbar_bottom - 5 };
  176.         click;
  177.         match [scrollBar w:[window ord:1] setting:?cntrl_value]!;
  178.         if(cntrl_value[1] = Previous_scroller_setting[1]) begin     # scroll value hasn't changed
  179.             Clicks_for_current_value := Clicks_for_current_value + 1;
  180.             for i := 1 to Clicks_for_current_value click;
  181.         end;
  182.         else begin
  183.             Clicks_for_current_value := 0;
  184.         end;
  185.         move absolute: { Scrollbar_left - 10,Scrollbar_top + 5 };
  186.     end;
  187.     click;    # Make the new selection
  188.     if (not Done_scrolling) begin
  189.         match [scrollBar w:[window ord:1] setting:?cntrl_value]!;
  190.         Previous_scroller_setting := cntrl_value;
  191.         if (cntrl_value[1] = cntrl_value[2]) begin
  192.             Done_scrolling := true;
  193.             List_item_height := 
  194.                 (Scrollbar_bottom - Scrollbar_top) / 7;    # 7 is the number of visible types
  195.             Non_top_item_selection := 2;                # now used to select remaining visible items 
  196.         end;
  197.     end;
  198. end; # end select_next_type() 
  199.  
  200.  
  201. # ********************************************************************************************
  202. # Checks for an alert and if one isn't there positions the window, else it logs the alert 
  203. task check_for_alert_or_position_window() begin
  204.     if(match[button w:[window ord:1 style:dialog] t:'OK']!) begin
  205.         text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
  206.         println "dismissing dialog that came up after resource type selection -- static text messages follow:";
  207.         for each m in text_messages println " ∂t",m.t;
  208.         select [button t:'OK'];
  209.     end;
  210.     else begin
  211.         position_res_type_window();
  212.     end;
  213. end;    # end check_for_alert_or_position_window() 
  214.  
  215.  
  216. (**************************************************************************************************** 
  217.     This task at the very least creates a window for each of the various resource types.  If
  218.     suppress_additional_actions is false, the task will call another task (to be determined later) 
  219.     which will strip the resource type from the window and call a task that will deal with the given
  220.     type of resource. pass a number to some_of_each if you only a want a certain number of resource
  221.     types created.  some_of_each should be 0 if you want all types;
  222. ****************************************************************************************************)  
  223. task create_one_of_each_type(suppress_additional_actions := true,some_of_each := 0) begin
  224.  
  225.     global Scrollbar_left,Scrollbar_top;
  226.     global Res_file_name;
  227.  
  228.     
  229.     set_scroll_bar_globals();
  230.     move absolute: { Scrollbar_left - 10,Scrollbar_top + 5 };
  231.     click;
  232.     select [button t:'OK']!;
  233.     check_for_alert_or_position_window();
  234.  
  235.     creations_count := 1;
  236.  
  237.     while ((global Non_top_item_selection <> 8) and  
  238.                                     ((not some_of_each) or (creations_count <> some_of_each))) begin
  239.             if(not match[window t:Res_file_name o:1]!) select [window t:Res_file_name]!;
  240.             select [menuItem title:'New' m:'File']!;
  241.             select_next_type();
  242.             creations_count := creations_count + 1;
  243.             select [button t:'OK']!;
  244.             check_for_alert_or_position_window();
  245.     end;
  246. end; # end create_one_of_each_type() *)
  247.  
  248.  
  249.  
  250. #####   EXECUTION STARTS HERE  ######
  251.  
  252. Done_scrolling := false;
  253. Clicks_for_current_value := 0;
  254.  
  255. Non_top_item_selection := 0;
  256.  
  257. Res_file_name := "vu-wants-1-of-each";
  258.  
  259. set_screen_dependents();
  260.  
  261. match[window o:1 t:?Volume_name]!;
  262.  
  263. create_resource_file(Res_file_name);
  264.  
  265. create_one_of_each_type(true,15);
  266.  
  267. verif_string := "window titles follow for verification";
  268. println "∂n",verif_string;
  269. for i := 1 to card(verif_string) print "=";
  270. println;
  271.  
  272. for each w in collect[window] println w.title; # ~~~~~~~~ to verify that all the windows were created
  273.  
  274. clear_file(Res_file_name,false);